/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.mse.camel.client.whiteboard.gef.whiteboard.impl;

import edu.mse.camel.client.whiteboard.gef.whiteboard.FreeWritingShape;
import edu.mse.camel.client.whiteboard.gef.whiteboard.WhiteboardPackage;
import edu.mse.camel.client.whiteboard.gef.whiteboard.XY;
import edu.mse.camel.client.whiteboard.gef.whiteboard.WhiteboardDiagram;

import java.util.Collection;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EObjectEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Free Writing Shape</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link edu.mse.camel.client.whiteboard.gef.whiteboard.impl.FreeWritingShapeImpl#getSize <em>Size</em>}</li>
 *   <li>{@link edu.mse.camel.client.whiteboard.gef.whiteboard.impl.FreeWritingShapeImpl#getLocation <em>Location</em>}</li>
 *   <li>{@link edu.mse.camel.client.whiteboard.gef.whiteboard.impl.FreeWritingShapeImpl#getID <em>ID</em>}</li>
 *   <li>{@link edu.mse.camel.client.whiteboard.gef.whiteboard.impl.FreeWritingShapeImpl#getPoints <em>Points</em>}</li>
 *   <li>{@link edu.mse.camel.client.whiteboard.gef.whiteboard.impl.FreeWritingShapeImpl#getColor <em>Color</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class FreeWritingShapeImpl extends EObjectImpl implements FreeWritingShape {
	/**
	 * The default value of the '{@link #getSize() <em>Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSize()
	 * @generated
	 * @ordered
	 */
	protected static final Dimension SIZE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getSize() <em>Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSize()
	 * @generated
	 * @ordered
	 */
	protected Dimension size = SIZE_EDEFAULT;

	/**
	 * The default value of the '{@link #getLocation() <em>Location</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocation()
	 * @generated
	 * @ordered
	 */
	protected static final Point LOCATION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getLocation() <em>Location</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocation()
	 * @generated
	 * @ordered
	 */
	protected Point location = LOCATION_EDEFAULT;

	/**
	 * The default value of the '{@link #getID() <em>ID</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getID()
	 * @generated
	 * @ordered
	 */
	protected static final String ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getID() <em>ID</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getID()
	 * @generated
	 * @ordered
	 */
	protected String id = ID_EDEFAULT;

	/**
	 * The cached value of the '{@link #getPoints() <em>Points</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPoints()
	 * @generated
	 * @ordered
	 */
	protected EList<XY> points;

	/**
	 * The default value of the '{@link #getColor() <em>Color</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getColor()
	 * @generated
	 * @ordered
	 */
	protected static final RGB COLOR_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getColor() <em>Color</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getColor()
	 * @generated
	 * @ordered
	 */
	protected RGB color = COLOR_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected  FreeWritingShapeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WhiteboardPackage.Literals.FREE_WRITING_SHAPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getID() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setID(String newID) {
		String oldID = id;
		id = newID;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WhiteboardPackage.FREE_WRITING_SHAPE__ID, oldID, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Point getLocation() {
		return location;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLocation(Point newLocation) {
		Point oldLocation = location;
		location = newLocation;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WhiteboardPackage.FREE_WRITING_SHAPE__LOCATION, oldLocation, location));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Dimension getSize() {
		return size;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSize(Dimension newSize) {
		Dimension oldSize = size;
		size = newSize;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WhiteboardPackage.FREE_WRITING_SHAPE__SIZE, oldSize, size));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<XY> getPoints() {
		if (points == null) {
			points = new EObjectContainmentEList<XY>(XY.class, this, WhiteboardPackage.FREE_WRITING_SHAPE__POINTS);
		}
		return points;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RGB getColor() {
		return color;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setColor(RGB newColor) {
		RGB oldColor = color;
		color = newColor;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WhiteboardPackage.FREE_WRITING_SHAPE__COLOR, oldColor, color));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WhiteboardPackage.FREE_WRITING_SHAPE__POINTS:
				return ((InternalEList<?>)getPoints()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WhiteboardPackage.FREE_WRITING_SHAPE__SIZE:
				return getSize();
			case WhiteboardPackage.FREE_WRITING_SHAPE__LOCATION:
				return getLocation();
			case WhiteboardPackage.FREE_WRITING_SHAPE__ID:
				return getID();
			case WhiteboardPackage.FREE_WRITING_SHAPE__POINTS:
				return getPoints();
			case WhiteboardPackage.FREE_WRITING_SHAPE__COLOR:
				return getColor();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WhiteboardPackage.FREE_WRITING_SHAPE__SIZE:
				setSize((Dimension)newValue);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__LOCATION:
				setLocation((Point)newValue);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__ID:
				setID((String)newValue);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__POINTS:
				getPoints().clear();
				getPoints().addAll((Collection<? extends XY>)newValue);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__COLOR:
				setColor((RGB)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WhiteboardPackage.FREE_WRITING_SHAPE__SIZE:
				setSize(SIZE_EDEFAULT);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__LOCATION:
				setLocation(LOCATION_EDEFAULT);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__ID:
				setID(ID_EDEFAULT);
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__POINTS:
				getPoints().clear();
				return;
			case WhiteboardPackage.FREE_WRITING_SHAPE__COLOR:
				setColor(COLOR_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WhiteboardPackage.FREE_WRITING_SHAPE__SIZE:
				return SIZE_EDEFAULT == null ? size != null : !SIZE_EDEFAULT.equals(size);
			case WhiteboardPackage.FREE_WRITING_SHAPE__LOCATION:
				return LOCATION_EDEFAULT == null ? location != null : !LOCATION_EDEFAULT.equals(location);
			case WhiteboardPackage.FREE_WRITING_SHAPE__ID:
				return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
			case WhiteboardPackage.FREE_WRITING_SHAPE__POINTS:
				return points != null && !points.isEmpty();
			case WhiteboardPackage.FREE_WRITING_SHAPE__COLOR:
				return COLOR_EDEFAULT == null ? color != null : !COLOR_EDEFAULT.equals(color);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (size: ");
		result.append(size);
		result.append(", location: ");
		result.append(location);
		result.append(", ID: ");
		result.append(id);
		result.append(", color: ");
		result.append(color);
		result.append(')');
		return result.toString();
	}
	  public WhiteboardDiagram getDiagram() {
	        if (eContainerFeatureID != WhiteboardPackage.FREE_WRITING_SHAPE__POINTS) return null;
	        return (WhiteboardDiagram)eContainer;
	    }
	 
	  public void setDiagram(WhiteboardDiagram diagram)  {
		  
	  }	  
	  public void setPoints(XY points[])
	    {
	    	List new_points = new ArrayList(points.length);
	        for(int i=0; i < points.length; i++)
	            new_points.add(points[i]);
	        setPoints(new_points);
	    }
	  public void setPoints(List <XY> points) 
	    {
	        getPoints().clear();
	        getPoints().addAll(points);
	    }
	
} //FreeWritingShapeImpl
